# -*- coding:utf-8 -*-
__author__ = 'xigu007'
from kivy.metrics import dp, sp
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import StringProperty,ListProperty
from kivy.lang import Builder
from composite_widget.base import RelativeComposite,Division
from composite_widget.content import LabelContent, ImageContent, ShapeContent
from composite_widget.group import ShapeBackground

Builder.load_string('''
<MyStyle@Division>
    text1: ''
    text2: ''
    image: ''
    bk_color: 1.0, 0.314, 0.294, 1
    Division:
        #Div占位权重,也就是说Div的宽（高）度由权重决定，如果已经设置了绝对宽（高）度或设置了与内容一样大小，该权重值被忽然。
        weight: 5
        orientation: 'vertical'
        Division:
            contents_typesetting: 'anchor'
            LabelContent:
                text: root.text1
                color: 0.2, 0.2, 0.2, 1
                font_size: sp(18)
                margin: 25,0,0,6
                #停靠左边
                anchor: 'left'
                #content下对齐DIV
                align: 'bottom'
        Division:
            contents_typesetting: 'anchor'
            ShapeBackground:
                color: root.bk_color
                radius: 8
                solid: False
                anchor: 'left'
                margin: 25,0,6,0
                align: 'top'
                LabelContent:
                    margin: 8,8,2,2
                    color: root.bk_color
                    text: root.text2
    Division:
        weight: 3
        ImageContent:
            source: root.image
            size_hint: None, 0.7
<Example2>
    #设置为白色背景
    canvas.before:
        Color:
            rgb: 1,1,1
        Rectangle:
            pos: 0,0
            size: self.size
        #背景分割线
        Color:
            rgb: 0.75,0.75,0.75
        Rectangle:
            pos: 0,0.5*self.height
            size: self.width,1
        Rectangle:
            pos: 0.5*self.width,0
            size: 1,self.height
    Division:
        #左边区域
        orientation: 'vertical'
        MyStyle:
            text1: '领15元饭贴'
            text2: '超值工作餐'
            image: 'res/demo_item1.png'

        MyStyle:
            text1: '10元看电影'
            text2: '零差评大片'
            image: 'res/demo_item3.png'
            bk_color: 0.278, 0.753, 0.792, 1

    Division:
        #右边区域
        orientation: 'vertical'
        MyStyle:
            text1: '外卖霸王餐'
            text2: '速抢50元'
            image: 'res/demo_item2.png'
            bk_color: 0.325, 0.58, 0.898, 1
        MyStyle:
            text1: '浪漫春日游'
            text2: '红包免费领'
            image: 'res/demo_item4.png'
            bk_color: 1.0, 0.51, 0.192, 1
''')

class Example2(RelativeComposite):
    pass
